package com.fancy.learncenter.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.fancy.learncenter.activity.base.BaseActivity;
import com.fancy.learncenter.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.adapter.base.CustomViewHold;
import com.fancy.learncenter.bean.BaseDataBean;
import com.fancy.learncenter.bean.YgtRecordDataBean;
import com.fancy.learncenter.net.HttpMehtod;
import com.fancy.learncenter.net.IdeaObserver;
import com.superservice.lya.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class YGTVipActivity extends BaseActivity {

    @Bind(R.id.title)
    TextView title;
    @Bind(R.id.recycleView)
    RecyclerView recycleView;
    @Bind(R.id.btn_right)
    TextView btnRight;
    @Bind(R.id.buy_time)
    TextView buyTime;
    @Bind(R.id.end_time)
    TextView endTime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ygt_vip, getResources().getColor(R.color.toolbar_color));
        ButterKnife.bind(this);
        title.setText("易沟通");
        buyTimeStr = getIntent().getStringExtra("buyTime");
        endTimeStr = getIntent().getStringExtra("endTime");

        buyTime.setText("购买时间:" + buyTimeStr);
        endTime.setText("到期时间:" + endTimeStr);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recycleView.setLayoutManager(linearLayoutManager);

        commonRecycleViewAdapter = new CommonRecycleViewAdapter<YgtRecordDataBean>(this, R.layout.activity_ygt_record_item, new ArrayList<YgtRecordDataBean>()) {
            @Override
            public void bindView(CustomViewHold customViewHold, YgtRecordDataBean item, int position) {

                TextView time = customViewHold.getView(R.id.time);
                time.setText(item.getPay_time());


                TextView price_num = customViewHold.getView(R.id.price_num);
                price_num.setText(item.getPrice());


            }
        };

        recycleView.setAdapter(commonRecycleViewAdapter);

        getData();
    }

    String buyTimeStr = "";
    String endTimeStr = "";

    @OnClick({R.id.back, R.id.chongzhi})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.chongzhi:
                Intent intent = new Intent(this, YgtPayActivity.class);
                intent.putExtra("", "");
                startActivity(intent);
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }

    int page = 0;

    private void getData() {
        Map maps = new HashMap();
        maps.put("page", page + "");
        HttpMehtod.getInstance().ygtRecoder(maps, new IdeaObserver<BaseDataBean<List<YgtRecordDataBean>>>() {


            @Override
            public void onSuccess(BaseDataBean<List<YgtRecordDataBean>> ygtPayDataBeanBaseDataBean) {

                if (ygtPayDataBeanBaseDataBean.getData() != null) {
                    commonRecycleViewAdapter.notifyDataSetChanged((ArrayList<YgtRecordDataBean>) ygtPayDataBeanBaseDataBean.getData());
                }
            }

            @Override
            public void onFail(int errorCode) {

            }

        });
    }

    CommonRecycleViewAdapter<YgtRecordDataBean> commonRecycleViewAdapter;
}
